/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include "MIpInterfaceInfo.h"

//---------------------------------------------------------------------------

MIpInterfaceInfo::MIpInterfaceInfo(void)
{
	Initialize();
}

MIpInterfaceInfo::~MIpInterfaceInfo(void)
{
}

//---------------------------------------------------------------------------

void MIpInterfaceInfo::Initialize(void)
{
	intfName.Empty();
	intfDesc.Empty();
	memset(&addrIP, 0, sizeof(in_addr));
	memset(&addrIPv6, 0, sizeof(in_addr6));
}

//---------------------------------------------------------------------------

bool MIpInterfaceInfo::IsIPv4Zero(void)
{
	return addrIP.S_un.S_addr==0 ? true : false;
}

bool MIpInterfaceInfo::IsIPv6Zero(void)
{
	if(addrIPv6.u.Word[0]!=0x0000) return false;
	if(addrIPv6.u.Word[1]!=0x0000) return false;
	if(addrIPv6.u.Word[2]!=0x0000) return false;
	if(addrIPv6.u.Word[3]!=0x0000) return false;
	if(addrIPv6.u.Word[4]!=0x0000) return false;
	if(addrIPv6.u.Word[5]!=0x0000) return false;
	if(addrIPv6.u.Word[6]!=0x0000) return false;
	if(addrIPv6.u.Word[7]!=0x0000) return false;

	return true;
}

//---------------------------------------------------------------------------

CString MIpInterfaceInfo::GetIPv4Name(void)
{
	CString str;
	str = inet_ntoa(addrIP);
	return str;
}

CString MIpInterfaceInfo::GetIPv6Name(void)
{
	CString str;
	str.Format(_T("%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"),
					addrIPv6.u.Word[0],
					addrIPv6.u.Word[1],
					addrIPv6.u.Word[2],
					addrIPv6.u.Word[3],
					addrIPv6.u.Word[4],
					addrIPv6.u.Word[5],
					addrIPv6.u.Word[6],
					addrIPv6.u.Word[7]);
	return str;
}

//---------------------------------------------------------------------------
